<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>props简写</title>

</head>
<body>
<div id="test"></div>
</body>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<!--将jsx转为js-->
<script src="../js/babel.min.js"></script>
<!--babel  由babel转换jsx-->
<script src="../js/prop-types.js"></script>

<script type="text/babel">
    //1.创建类式组件
    class Person extends React.Component {
        constructor(props) {
            super(props);
            // props若不接不传，this.props 为undefined，构造器若需要通过实例渠道props则需要写，其他情况不写
            // console.log('constructor',this.props)
        }
        static propTypes = {
            name: PropTypes.string.isRequired,
            sex: PropTypes.string,
            age: PropTypes.number,
        }
        static defaultProps = {
            sex: '男',
            age: 18
        }

        render() {
            const {name, age, sex} = this.props
            return (
                <ul>
                    <li>姓名：{name}</li>
                    <li>性别：{sex}</li>
                    <li>年龄:{parseInt(age) + 1}</li>
                </ul>
            )
        }
    }

    //2.渲染组件到页面
    const p = {
        name: '张三',
    }
    ReactDOM.render(<Person {...p}/>, document.getElementById('test'))
</script>
</html>